package com.lzw.breezeNovel.webApp.controller.novel;

import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.query.PaginationResultQuery;
import com.lzw.breezeNovel.webApp.service.novel.ReadRecordService;
import com.lzw.breezeNovel.webApp.vo.novel.BookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.controller
 * @date 2025/3/2
 * @description 阅读记录的控制类
 */
@RestController
@RequestMapping("/app/readRecord")
@SuppressWarnings("all")
public class ReadRecordController {

    /**
     * 注入阅读记录服务类
     */
    @Autowired
    private ReadRecordService readRecordService;

    /**
     * 获取最新的阅读记录
     */
    @GetMapping("/getLatestReadRecord")
    public Result<BookVo> getLatestReadRecord(){
        BookVo book = readRecordService.getLatestReadRecord();
        return Result.ok(book);
    }

    /**
     * 分页获取浏览记录
     */
    @GetMapping("/getRecord")
    public Result<PaginationResultQuery<BookVo>> getReadRecordList(@RequestParam Integer page, @RequestParam Integer pageSize){
        PaginationResultQuery<BookVo> bookVoList = readRecordService.getReadRecordList(page, pageSize);
        return Result.ok(bookVoList);
    }

    /**
     * 根据id删除阅读记录
     */
    @DeleteMapping("/deleteReadRecord")
    public Result deleteReadRecord(@RequestParam Integer bookId){
        readRecordService.deleteReadRecord(bookId);
        return Result.ok();
    }

    /**
     * 根据书籍id,章节id保存浏览记录
     */
    @GetMapping("/saveReadRecord")
    public Result saveReadRecord(@RequestParam Integer bookId, @RequestParam Integer chapterNumber){
        readRecordService.saveReadRecord(bookId, chapterNumber);
        return Result.ok();
    }


}

